<template>
  <div>
    <el-card style="min-width: 1200px">
      <div class="tableSelectWrap">
        <el-form ref="transferForm" :model="dataForm" label-width="100px">
          <el-row>
            <el-col :span="7">
              <el-form-item label="选择时间" prop="date">
                <el-date-picker
                  :default-time="['00:00:00', '23:59:59']"
                  style="width: 100%"
                  v-model="dataForm.date"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  type="datetimerange"
                  clearable
                  range-separator="-"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>

            <el-col
              :span="7"
              :offset="1"
              :style="{ display: this.dataForm.channel ? 'flex' : '' }"
            >
              <el-form-item label="支付渠道" prop="channel">
                <el-select
                  v-model="dataForm.channel"
                  class="leftSelect"
                  style="width: 100%"
                  placeholder="请选择支付渠道"
                  clearable
                  @change="handleChannel"
                >
                  <el-option
                    v-for="(item, index) of payChannel"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
              <el-form-item
                label=""
                prop="channelType"
                label-width="0"
                v-if="dataForm.channel"
              >
                <el-select
                  class="rightSelect"
                  v-model="dataForm.channelType"
                  style="width: 100%"
                  placeholder="请选择"
                  clearable
                >
                  <el-option
                    v-for="(item, index) of payChannelTypeList"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="7" :offset="1">
              <el-form-item label="红包状态" prop="status">
                <el-select
                  clearable
                  v-model="dataForm.status"
                  style="width: 100%"
                  placeholder="请选择红包状态"
                >
                  <el-option
                    v-for="item of payStateList"
                    :key="item.id"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="7" :offset="0" style="min-width: 170px">
              <el-button
                class="width120"
                @click="
                  () => {
                    resetForm('transferForm');
                    payChannelTypeList = [];
                    dataForm.orderNo = '';
                  }
                "
                >重置</el-button
              >
              <el-button type="primary" class="width120" @click="handleQuery"
                >查询</el-button
              >
            </el-col>
          </el-row>
        </el-form>
      </div>
    </el-card>
    <el-card style="margin-top: 20px; min-width: 1200px">
      <div class="switch">
        <el-switch v-model="isFixedTableH" inactive-text="固定表头">
        </el-switch>
      </div>
      <el-table :data="dataList" :height="fixedTableHeight">
        <template slot="empty">
          <el-empty
            :image="require('@/assets/imgs/middleWork/k1.png')"
            :image-size="80"
            description="暂无相关数据"
          ></el-empty>
        </template>
        <el-table-column
          show-overflow-tooltip
          prop="gmtCreated"
          align="center"
          label="创建时间"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{ scope.row.gmtCreated ? scope.row.gmtCreated : "-" }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="redNo"
          align="center"
          label="商户订单号"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{ scope.row.redNo ? scope.row.redNo : "-" }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="fmtAmount"
          align="center"
          label="付款金额/元"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{ scope.row.fmtAmount ? scope.row.fmtAmount : "0.00" }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="subject"
          align="center"
          label="活动名称"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{ scope.row.subject ? scope.row.subject : "-" }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="channel"
          align="center"
          label="支付渠道"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{ scope.row.channelName ? scope.row.channelName : "-" }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="status"
          align="center"
          label="红包状态"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
              :style="{
                color:
                  scope.row.status == 'sending' || scope.row.status == 'send'
                    ? '#EE8917'
                    : scope.row.status == 'failed'
                    ? '#E23D28'
                    : '',
              }"
            >
              {{ scope.row.status ? setPayStatus(scope.row.status) : "-" }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="act"
          align="center"
          label="操作"
          width="100"
        >
          <template slot-scope="scope">
            <el-button type="text" @click="handleDetails(scope.row)"
              >详情</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <el-pagination
      layout="prev, pager, next, sizes, jumper"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="pageSize"
      :current-page="pageNum"
      :total="total"
      @current-change="pageCurrentChangeHandle"
      @size-change="pageSizeChangeHandle"
    >
    </el-pagination>
  </div>
</template>

<script>
import mixin from "@/mixins/mixin";
export default {
  name: "weChatRedPacket",
  mixins: [mixin],
  data() {
    return {
      dataList: [],
      mixinViewModuleOptions: {
        // createdIsNeed: false,
        getDataListURL: "/api/merchant/redPacketInfo/searchByPage",
      },
      payStateList: [
        // 红包状态
        { id: 1, label: "所有", value: "" },
        { id: 2, label: "发放中", value: "sending" },
        { id: 3, label: "发放待领取", value: "send" },
        { id: 4, label: "发放失败", value: "failed" },
        { id: 5, label: "已领取", value: "received" },
        { id: 6, label: "退款中", value: "rfunding" },
        { id: 7, label: "已退款", value: "refund" },
      ],
      payChannel: [],
      // payChannel: this.$store.state.channelList,
      payChannelType: this.$store.state.channelListType,
      payChannelTypeList: [],
      info: {},

      dataForm: {
        status: "",
        channelType: "",
        channel: "",
        date: [],
      },
    };
  },
  created() {
    if (!this.dataForm.channel) {
      this.payChannelTypeList = [{ id: 1, label: "所有", value: "" }];
    }
    this.getChannelList();
  },
  watch: {
    "$store.state.testLine": {
      handler() {
        if (this.$route.name == this.$options.name) {
          this.handleQuery();
        }
      },
    },
    deep: true,
  },
  methods: {
    getChannelList() {
      this.$http.get("/api/dict/channelList").then((res) => {
        if (res.code === "0000") {
          var a = [{ label: "所有", value: "" }];
          var b = a.concat(res.data);
          this.payChannel = b;
        }
      });
    },
    handleDetails(row) {
      this.$router.push({
        path: "/marketingTool/weChatRedPacket/detail",
        query: { id: row.id },
      });
    },
    setPayStatus(val) {
      let str = "";
      switch (val) {
        case "sending":
          str = "发放中";
          break;
        case "send":
          str = "发放待领取";
          break;
        case "failed":
          str = "发放失败";
          break;
        case "received":
          str = "已领取";
          break;
        case "rfunding":
          str = "退款中";
          break;
        case "refund":
          str = "已退款";
          break;
      }
      return str;
    },

    handleChannel(val) {
      if (val) {
        this.payChannelTypeList = this.payChannelType[val];
      } else {
        this.payChannelTypeList = [];
      }
      this.dataForm.channelType = "";
    },
    handleQuery() {
      if (this.dataForm.date && this.dataForm.date.length) {
        this.dataForm.gmtCreatedBegin = this.dataForm.date[0];
        this.dataForm.gmtCreatedEnd = this.dataForm.date[1];
      } else {
        this.dataForm.gmtCreatedBegin = "";
        this.dataForm.gmtCreatedEnd = "";
      }
      this.getDataList();
    },
  },
};
</script>

<style scoped lang="scss">
.switch {
  margin-bottom: 20px;
}
.ml {
  margin-left: 50px;
}
.search {
  position: absolute;
  right: 0;
  top: -164px;
}
</style>
